<?
	include("common.php");
	include("pop_header.php");
	
	if( $_POST['username'] && $_POST['password'] && $_POST['email'] && $_POST['name'] ){
		$posterr = 0;
		$name = $_POST['name'];
		$username = $_POST['username'];
		$password = $_POST['password'];
		$email = $_POST['email'];

		$r = @mysql_fetch_row( @mysql_query("SELECT id FROM users WHERE username='".addslashes($_POST['username'])."'"));
		if ($r[0]){
			errform('The username you have chosen already exists. Please pick another.', 'username'); // #err
		}
		$r = @mysql_fetch_row( @mysql_query("SELECT id FROM users WHERE email='".addslashes($_POST['email'])."'"));
		if ($r[0]){
			errform('The email address you have chosen is already registered. Please pick another.', 'email'); // #err
		}

		$newpass = $_POST['password'];
		$newpass2 = $_POST['password2'];
		if( $newpass != $newpass2 ){
			errform('the password must match what you re-type'); // #err
		}
		if( !$posterr ){
			$qr1 = mysql_query("INSERT INTO users SET 
					username='$username',
					password='$password',
					email='$email',
					forum='".$_POST['forum']."',
					type='1',
					address='".$_POST['address']."',
					homepage='".$_POST['homepage']."',
					icq='".$_POST['icq']."',
					aol='".$_POST['aol']."',
					yahoo='".$_POST['yahoo']."',
					msn='".$_POST['msn']."',
					interest='".$_POST['interest']."',
					ocupation='".$_POST['ocupation']."',
					joined=".time().",
					name='$name'") or die( mysql_error() );
			$uid = mysql_insert_id();
			if( $signupb ){
				transact("0",$uid,$signupb,"signup bonus");
			}
#echo $uid."<br>";			
		}
	}
	if($uid){
		echo "Thank You for Joining $sitename<br>";
		echo "<a href='login.php'>Click here</a> to login to your account<br>";
	}else{
?>
		<SCRIPT LANGUAGE="JavaScript">
		<!-- Begin
			function reset() {
				document.register.username.value="";
				document.register.password.value="";
				document.register.password2.value="";
				document.register.email.value="";
				document.register.name.value="";
			}
			function checkFields() {   
				if ( (document.register.username.value=="") ){
					alert("Please enter username!");
					return false;
				}
				if ( (document.register.password.value=="") ){
					alert("Please enter password!");
					return false;
				}
				if ( (document.register.password2.value=="") ){
					alert("Please verify password!");
					return false;
				}
				if ( (document.register.email.value=="") ){
					alert("Please enter email address!");
					return false;
				}
				if ( (document.register.name.value=="") ){
					alert("Please enter a name!");
					return false;
				}
				var frm = document.forms["register"];
				if(frm.password.value != frm.password2.value){
					alert('The password and verified password do not match!');
					return false;
				}else{
					return true;
				}
			}
		//  End -->
		</script>
		<p><font face=arial size=3>
		<table width=100%>
		<tr><form action="joinforum.php" method="POST" name="register" onsubmit="return checkFields()"><input type="hidden" name="forum" value="<?=$forum?>">
			<td><font face="arial" size="2"><b>Your Name (required)</b></td>
			<td><font face="arial" size="2"><input type=text name=name size=30 maxlength="30" value="<?=$_POST['name']?>"><i> [2-12 characters]</i></td>
		</tr>
		<tr>
			<td><font face="arial" size="2"><b>Username (required)</b></td>
			<td><font face="arial" size="2"><input type=text name=username size=30 maxlength="30" value="<?=$_POST['username']?>"><i> [2-12 characters]</i></td>
		</tr>
		<tr>
			<td><font face="arial" size="2"><b>Password (required)</b></td>
			<td><font face="arial" size="2"><input type=password name=password size=30 maxlength="12"><i> [5-12 characters]</i></font></td>
		</tr>
		<tr>
			<td><font face="arial" size="2"><b>Verify Password (required)</b></td>
			<td><font face="arial" size="2"><input type=password name=password2 size=30 maxlength="12"><i>[re-enter password]</i></font></td>
		</tr>
		<tr>
			<td><font face="arial" size="2"><b>Email Address (required)</b></td>
			<td><font face="arial" size="2"><input type=input name=email size=30 maxlength="40" value="<?=$_POST['email']?>"><i> [valid email address]</i></td>
		</tr>
		<tr>
			<td colspan=2><font face="arial" size="2"><br>
				<input type="hidden" name="action" value="create"><br>
				<font face="arial" size="2"><input type="submit" value="Register" tabindex="6" style="background-color:#e5e5e5; color:#000000; font-family:Verdana,Arial; font-weight: bold; font-size: 11px; border-left: 1 solid #a0a0a0; border-top: 1 solid #a0a0a0; border-right: 1 solid #000000; border-bottom: 1 solid #000000; padding: 2 2 2 2; outline: #a0a0a0 solid 2px;">
			</td>
		</tr>
		</table>
		</form>
		<p>
<?
	}
	include("pop_footer.php");
?>